package neuroPoker.training;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

import neuroPoker.netze.PokerNetLoader;

public class TrainFrame extends JFrame {
	private static final long serialVersionUID = 2058927078980360158L;

	public JButton saveButton = new JButton("Speichern");

	public PokerNetLoader netLoad;

	public Trainer trainer;

	public String folder;

	public int trained;

	public Thread trainThread;

	public TrainFrame(Trainer trainer) {
		super("TrainFrame");

		this.netLoad = trainer.netload;
		this.trainer = trainer;

		folder = trainer.folder;
		trained = Integer.parseInt(trainer.path.substring(
				trainer.path.indexOf("/") + 1, trainer.path.length()));

		saveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				save();
			}
		});
		this.setLayout(new FlowLayout());

		this.getContentPane().add(saveButton);
		this.setPreferredSize(new Dimension(300, 100));
		saveButton.setPreferredSize(new Dimension(120, 20));

		this.pack();
		this.setVisible(true);

		trainThread = Thread.currentThread();
	}

	public void save() {
		Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
		int trainedSpiele = trained + trainer.anzSpiele;
		netLoad.saveAll(folder + "/" + trainedSpiele);
		System.out.println("Saved: " + folder + "/" + trainedSpiele);

	}

}
